﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySpace.Data;
using DataBaseTable;

public partial class DengXin_list : System.Web.UI.Page
{
    private string PeriodsId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["PeriodsId"]))
            {
                this.PeriodsId = Request.QueryString["PeriodsId"];
                this. DataBd();
            }
        }
    }
    protected void DataBd()
    {
        DBHandler dbh = GetHandler.Init();
        dbh.CommandText = string.Format("select * from DengXinCatalogue where ForPeriodsId={0} order by CatalogueId asc", this.PeriodsId);
        Periods_repeater.DataSource = dbh.ExecuteDataTable();
        Periods_repeater.DataBind();
        DengXinBookTable dxbt = new DengXinBookTable(Convert.ToInt32( this.PeriodsId));
        this.PeriodsTitle .Text= dxbt.PeriodsName;
        if (!string.IsNullOrEmpty(dxbt.Cover))
        {
            this.Cover.Visible = true;
            this.Cover.ImageUrl = "~/DengXinCover/" + dxbt.Cover;
        }
        PublishYear_lb.Text = dxbt.PublishYear;
        Master.WebSubTitle  += dxbt.PeriodsName+"-";
    }
    protected void Periods_repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rp = (Repeater)e.Item.FindControl("article_repeater");
            Label lb = (Label)e.Item.FindControl("CatalogueId");
            int cid = Convert.ToInt32(lb.Text.ToString());
            DBHandler dbh = GetHandler.Init();
            dbh.CommandText = string.Format("select * from DengXinArticle where ChapterId={0} order by id desc", cid);
            rp.DataSource = dbh.ExecuteDataTable();
            rp.DataBind();
        }
    }
}